<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:c="http://java.sun.com/jsp/jstl/core"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                template="./../template/WorkspaceTemplate.xhtml">

    <ui:define name="top">
        
    </ui:define>

    <ui:define name="left">
    </ui:define>

    <ui:define name="right">
        
    </ui:define>

    <ui:define name="content">

        <h2>Manage Member Discount Group</h2>
        <h:form>
            <p:panel id="panel" header="Create/Update Member Discount Group">
                <p:messages showDetail="true"/>
                <h:panelGrid columns="2" cellpadding="10">
                    
                    <h:outputLabel style="font-weight: bold" value="Member Discount Group: "/>
                    <p:inputText id="group" value="#{mdgManagerBean.mdg.group}" label="Member Discount Group"/>
                    
                    <h:outputLabel style="font-weight: bold" value="Accumulated Spending (Whole Sales): "/>
                    <p:inputText id="accuSpendingWs" value="#{mdgManagerBean.mdg.accSpendingForWs}" label="Spending (Whole Sales)"/>
                    
                    <h:outputLabel style="font-weight: bold" value="Accumulated Spending (Direct Sales): "/>
                    <p:inputText id="accuSpendingDs" value="#{mdgManagerBean.mdg.accSpendingForDs}" label="Spending (Direct Sales)"/>
                    
                    <h:outputLabel style="font-weight: bold" value="Member Discount: "/>
                    <p:inputText id="memberDiscountGroup" value="#{mdgManagerBean.mdg.memberDiscount}" label="Member Discount"/>
                    
                </h:panelGrid>
            </p:panel>
            <p:commandButton id="button" value="Save Member Discount Group" ajax="false" action="#{mdgManagerBean.createMemberDiscountGroup(1)}"
                             image="ui-icon ui-icon-disk" update="panel,display"/>
            <p:commandButton id="cancel" value="Cancel" ajax="false" action="#{mdgManagerBean.createMemberDiscountGroup(0)}"/>
        </h:form>
        <br/><br/>
        
        <h:form>
            <p:panel id="panel" header="List of Member Discount Group">
                <br/>
                <p:dataTable  styleClass="allaroundborder" value="#{mdgManagerBean.viewAllMemberDiscount()}" var="mdg"
                              paginator="true" rows="5">

                    <p:column sortBy="#{mdg.group}" filterBy="#{mdg.group}">
                        <f:facet name="header">
                            <h:outputText value="Discount Group" />
                        </f:facet>
                        <h:outputText value="#{mdg.group}" />
                    </p:column>
                    
                    <p:column sortBy="#{mdg.accSpendingForWs}" filterBy="#{mdg.accSpendingForWs}">
                        <f:facet name="header">
                            <h:outputText value="AS(WS)" />
                        </f:facet>
                        <h:outputText value="#{mdg.accSpendingForWs}" />
                    </p:column>
                    
                    <p:column sortBy="#{mdg.accSpendingForDs}" filterBy="#{mdg.accSpendingForDs}">
                        <f:facet name="header">
                            <h:outputText value="AS(DS)" />
                        </f:facet>
                        <h:outputText value="#{mdg.accSpendingForDs}" />
                    </p:column>
                    
                    <p:column sortBy="#{mdg.memberDiscount}" filterBy="#{mdg.memberDiscount}">
                        <f:facet name="header">
                            <h:outputText value="Discount" />
                        </f:facet>
                        <h:outputText value="#{mdg.memberDiscount}" />
                    </p:column>
                    
                    <p:column>
                        <p:commandButton id="update" value="Update" ajax="false" action="#{mdgManagerBean.updateMemberDiscountGroup(mdg.id)}"
                                         update="panel,display">
                        </p:commandButton>
                        <p:commandButton id="delete" value="Delete" action="#{mdgManagerBean.beforeDelete(mdg.id)}" oncomplete ="confirmation.show()"
                                         update="panel,display">
                        </p:commandButton>
                    </p:column>
                </p:dataTable>
            </p:panel>
        </h:form>
        
        <h:form>
        <p:confirmDialog message="Are you sure?" width="200"  
                         showEffect="explode" hideEffect="explode"  
                         header="Confirm" severity="alert" widgetVar="confirmation">  
            
            <p:commandButton id="yes" value="Yes" ajax ="false" update="panel,display" action="#{mdgManagerBean.deleteMemberDiscountGroup()}" onstart="confirmation.hide()"/>  
            <p:commandButton id="cancel" value="Cancel" oncomplete="confirmation.hide()" />  
            
        </p:confirmDialog> 
        </h:form>

    </ui:define>

    <ui:define name="bottom">
       
    </ui:define>

</ui:composition>
